/**
 * Used for complex HP rules, the special stat counter contains a 2nd counter.
 * where after a set amount has been deceased the max is reduced
 * @author paul
 *
 */
public class StatCounterSpeical extends StatCounter {

	
	private int tmpMax;
	private int fatigueNum;
	private final int fatigueMax;
	
	public  StatCounterSpeical (int max, double regenerate, int fatigueMax)
	{
		super(max,regenerate);
		this.tmpMax = this.max;
		this.fatigueMax = fatigueMax;
		this.fatigueNum = fatigueMax;
	}
	
	/**
	 * gets the tmpMax  value
	 * @return
	 */
	public int getTmpMax()
	{
		return this.tmpMax;
	}
	/**
	 * current total is decrease
	 * @param x - amount to decrease by
	 */
	public void decrease(int x)
	{
		this.current = this.current - x;
		this.fatigueNum = this.fatigueNum - x;
		
		while (this.fatigueNum < 0)
		{
			this.fatigueNum = this.fatigueNum + this.fatigueMax;
			this.tmpMax--;
		}

	}
	
	/**
	 * current total is increase
	 * @param x - amount to restore by
	 */
	
	public void increase(int x)
	{
		this.current = this.current + x;
		if(this.current > this.tmpMax)
		{
			this.current = this.tmpMax;
		}
	}
	/**
	 * used each turn to regenerate a set amount
	 */
	public void regenerate()
	{
		int x = (int) ((this.regenerate * 100) / 100);
		this.remain = this.remain + (int) ((this.regenerate * 100) % 100);
		if (this.remain >= 100)
		{
			this.remain = this.remain - 100;
			x++;
		}
		this.current = this.current + x;
		if (this.current > this.tmpMax)
		{
			this.current = this.tmpMax;
		}
		
	}
	/**
	 * all stats are set to initial values is set to max
	 */
	public void fullRestore()
	{
		this.current = this.max;
		this.tmpMax = this.max;
		this.fatigueNum = this.fatigueMax;
	}
	/**
	 * returns a string of an easy to read state of stat
	 */
	public String toString()
	{
		return this.current + "/" + this.tmpMax 
				+ " (" +this.regenerate+ ")";
	}
	
	
}
